using JT808Protocol.Common;
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace JT808Protocol.Models.BodyParserStrategy
{
    /// <summary>
    /// 摄像头立即拍照应答
    /// </summary>
    public class DpSnapShot_0x0805 : IJT808Body
    {
        private byte _result { get; set; }
        private byte[] _mediaIDList { get; set; }

        /// <summary>
        /// 应答流水号
        /// </summary>
        [JsonPropertyName("应答流水号")] public ushort ReqSn { get; set; }

        /// <summary>
        /// 结果  0：成功；1：失败；2：通道不支持。
        /// </summary>
        [JsonPropertyName("结果")] public int ResultValue { get { return Convert.ToInt32(_result); } }

        /// <summary>
        /// 多媒体ID个数
        /// </summary>
        [JsonPropertyName("多媒体ID个数")] public ushort MediaIDCount { get; set; }

        /// <summary>
        /// 多媒体ID列表
        /// </summary>
        [JsonPropertyName("多媒体ID列表")] public string[] MediaIDList { get; set; }

        public override IJT808Body ReadBody(ReadOnlySpan<byte> source, ref int startIndex)
        {
            ReqSn = ParseHelper.Uint16(ref source, startIndex);
            _result = source[startIndex + 2];
            MediaIDCount = ParseHelper.Uint16(ref source, startIndex + 3);
            var mediaStartIndex = startIndex + 4;

            MediaIDList = new string[MediaIDCount];
            for (int i = 0; i < MediaIDCount; i++)
            {
                MediaIDList[i] = ParseHelper.AsciiString(ref source, mediaStartIndex + (i * 4), 4);
            }
            return this;
        }

        public override List<byte> WriteToBytes()
        {
            throw new NotImplementedException();
        }
    }
}